package com.water.camera.mark;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.water.camera.bean.EditItem;
import com.water.camera.databinding.LayoutWatermark71Binding;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

public class Mark71 extends BaseMark {

    LayoutWatermark71Binding binding;

    public Mark71(@NonNull Context context) {
        super(context);
    }

    public Mark71(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Mark71(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void init(int type) {
        if (type == 0) {
            binding = LayoutWatermark71Binding.inflate(LayoutInflater.from(getContext()));
            addView(binding.getRoot());
            for (int i = 3; i < binding.mid.getChildCount(); i++) {
                binding.mid.getChildAt(i).setVisibility(View.GONE);
            }
        } else {
            binding = LayoutWatermark71Binding.inflate(LayoutInflater.from(getContext()), this, true);
        }
        update();
    }

    @Override
    public void update() {
        setText(binding.binding2, "phone71", binding.binding1);
        setText(binding.binding4, "jingwei71", binding.binding3);
        String[] s = new EditItem("jingwei71").getStringPoints();
        binding.binding4.setText(s[1]);
        binding.binding6.setText(s[0]);
        setText(binding.binding8, "didian71", binding.binding7);
        setText(binding.binding10, "time71", binding.binding9);
        setTime(binding.binding10, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
        setText(binding.binding12, "height71", binding.binding11);
        setText(binding.binding14, "weather71", binding.binding13);
        setText(binding.binding14, "weather71", binding.binding13);
        setText(binding.binding16, "imei71", binding.binding15);
        setText(binding.binding18, "beizhu71", binding.binding17);

        super.update();
    }

    @Override
    public ArrayList<EditItem> getEditItems() {
        ArrayList<EditItem> list = new ArrayList<>();
        list.add(new EditItem("phone71", "手机号"));
        list.add(new EditItem("jingwei71", "经纬度"));
        list.add(new EditItem("didian71", "地点"));
        list.add(new EditItem("time71", "时间", true));
        list.add(new EditItem("height71", "海拔"));
        list.add(new EditItem("weather71", "天气"));
        list.add(new EditItem("imei71", "IMEI"));
        list.add(new EditItem("beizhu71", "备注"));

        return list;
    }

    @Override
    public void onValueChange(EditItem item) {
        if (item.isTime) {
            setTime(binding.binding6, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
        } else {
            super.onValueChange(item);
        }
    }
}
